<template>
  <div class="project-progress-container">
    <h1>项目进度管理</h1>
    <div class="filter-toolbar">
      <el-select v-model="selectedClass" placeholder="选择班级" @change="filterProjects">
        <el-option
          v-for="classItem in classes"
          :key="classItem"
          :label="classItem"
          :value="classItem"
        ></el-option>
      </el-select>
      <el-button type="primary" @click="filterProjects">搜索</el-button>
    </div>
    <el-table :data="filteredProjects" style="width: 100%">
      <el-table-column prop="name" label="项目名称" width="180"></el-table-column>
      <el-table-column prop="group" label="所属小组" width="180"></el-table-column>
      <el-table-column prop="class" label="所属班级" width="180"></el-table-column>
      <el-table-column label="操作" width="180">
        <template #default="scope">
          <el-button type="primary" @click="viewProject(scope.row)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()

const projects = ref([
  { id: 1, name: '项目1', group: '小组A', class: '班级1' },
  { id: 2, name: '项目2', group: '小组B', class: '班级2' },
  { id: 3, name: '项目3', group: '小组C', class: '班级3' },
  // 更多项目
])

const classes = ref([...new Set(projects.value.map(project => project.class))])

const selectedClass = ref('')
const filteredProjects = ref([...projects.value])

const filterProjects = () => {
  if (selectedClass.value) {
    filteredProjects.value = projects.value.filter(project => project.class === selectedClass.value)
  } else {
    filteredProjects.value = [...projects.value]
  }
}

const viewProject = (project) => {
  // 处理查看项目逻辑
  // 可以根据项目名称或其他信息进行路由跳转
  router.push({ name: 'project-view', params:{id: project.id} })
}
</script>

<style scoped>
.project-progress-container {
  padding: 20px;
  max-width: 1000px;
  margin: auto;
}

h1 {
  text-align: center;
  margin-bottom: 20px;
  color: #333;
  font-weight: 700;
}

.filter-toolbar {
  margin-bottom: 20px;
  display: flex;
  justify-content: flex-start;
  align-items: center;
}

.filter-toolbar .el-select {
  margin-right: 10px;
}
</style>
